package dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;

import org.apache.naming.java.javaURLContextFactory;

import bean.Customer;
import bean.Orders;
import bean.Room;
import common.util.DBUtils;
import common.util.UUIDUtils;
import dao.OrderDao;

public class OrderDaoImpl implements OrderDao {

	@Override
	public boolean insert(Orders t) throws SQLException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void deleteById(String id) throws SQLException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void update(Orders t) throws SQLException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Orders queryByid(String id) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Orders> queryAll() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean addOrder(Customer c,Room room, int pcount) throws SQLException {

		//创建连接
		Connection conn = DBUtils.getConnection();
		
		
		//数据操作
		String sql = "insert into orders values(?,?,?,?,?,?,?)";
		PreparedStatement psmt = conn.prepareStatement(sql);
		psmt.setString(1, UUIDUtils.getId());
		psmt.setString(2, null);
		psmt.setString(3, c.getCustomerId());
		psmt.setString(4, room.getRoomId());
		
		java.util.Date t = new Date();
		
		long time = t.getTime();
		java.sql.Date sqlTime = new java.sql.Date(System.currentTimeMillis());	
		psmt.setDate(5, sqlTime);	
		System.out.println(sqlTime);
		
		psmt.setInt(6, pcount);
		psmt.setInt(7, 1);
		
		psmt.executeUpdate();
		
		int index = psmt.getUpdateCount();
		
		//③ 关闭资源
		DBUtils.closeResource(conn, psmt);
		
		return index == 1 ? true : false;
		
	}
	
}
